//
//  HeadView.m
//  A手工客
//
//  Created by 萌萌的小坤坤 on 16/6/13.
//  Copyright © 2016年 冷坤. All rights reserved.
//

#import "HeadView.h"
#import "LKCycleView.h"
#import "HeadCollectionView.h"
#import "HeadImageView.h"
#import "AdvanceModel.h"
#define WIDTH self.view.frame.size.width

#define HEIGHT self.view.frame.size.height

#define COLORS [UIColor colorWithRed:(arc4random() % 256 / 255.0) green:(arc4random() % 256 / 255.0) blue:(arc4random() % 256 / 255.0) alpha:1.0];

@implementation HeadView
- (instancetype)initWithFrame:(CGRect)frame DiscoveryArray:(NSArray *)array RotateArray:(NSArray *)rotateArray ImageArray:(NSArray *)imageArray
{
    self = [super initWithFrame:frame];
    if (self) {
        [self rotateView:frame RotateArray:rotateArray DiscoveryArray:array ImageArray:imageArray];
    }
    return self;
}
// 轮播图
- (void)rotateView:(CGRect)frame RotateArray:(NSArray *)rotateArray DiscoveryArray:(NSArray *)disArray ImageArray:(NSArray *)imageArray{
    NSMutableArray *array = [NSMutableArray array];
    for (NSInteger i = 0; i < 7; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg",i]];
        [array addObject:image];
    }
    LKCycleView *cycleView = [[LKCycleView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, frame.size.height / 5 * 2) DataSource:rotateArray TimeInterval:2];
    //    cycleView.delegate = self;
    [self addSubview:cycleView];
    
    HeadCollectionView *collectionView = [[HeadCollectionView alloc] initWithFrame:CGRectMake(0, cycleView.frame.size.height, cycleView.frame.size.width, frame.size.height / 5)];
    [self addSubview:collectionView];
    collectionView.array = disArray;
    [collectionView release];
    
    HeadImageView *imageView = [[HeadImageView alloc] initWithFrame:CGRectMake(0, collectionView.frame.size.height + collectionView.frame.origin.y + 5, cycleView.frame.size.width, frame.size.height - collectionView.frame.size.height - cycleView.frame.size.height - 5)];
    
    // 取处数组对应的模型
    AdvanceModel *mdoelLeft = imageArray.firstObject;
    AdvanceModel *modelRight = imageArray.lastObject;
    
    // 获取网络图片
    UIImage *imageLeft = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:mdoelLeft.pic]]];
    UIImage *imageRight = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:modelRight.pic]]];
    
    // 给button赋网络图片
    [imageView.photoLeft setImage:imageLeft forState:UIControlStateNormal];
    [imageView.photoRight setImage:imageRight forState:UIControlStateNormal];
    
    [self addSubview:imageView];
}



@end
